<!doctype html>
<html ng-app="app">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../build/common/base.css" rel="stylesheet">
<script type="text/javascript" src="../../build/common/base.js"></script>
<script type="text/javascript" src="../../build/common/ngEdit.js"></script>
</head>
<script type="text/javascript">
	var id = $.getParam("id");
	var app = angular.module('app', [ 'baseDirective' ]);
	app.controller("ctrl", [ '$scope', 'baseService','ArrayToolService', 
			function($scope, baseService,ArrayToolService) {
				$scope.ArrayTool = ArrayToolService;
				$scope.isSaveEd = id;
				if(id){
					/* $("#followupTime").attr("disabled","disabled");
					window.onload=function(){
						setTimeout(function(){ $(".customerListButton").remove(); }, 10)
						$(".customerListSelect").remove();
					} */
				}
				
				/**
				 * 数据初始化。
				 */
				$scope.init=function(){
					if(!$scope.data){
						$scope.data={};
					}
				};
				
				$scope.selectCustomerList = function(){
					if(!$scope.data){
			 			$scope.data={};
			 		}
			 		if(!$scope.data.customerList){
			 			$scope.data.customerList = [];
			 		}
			 		var arr = [];
			 		var newList = [];
					for(var i=0,customer;customer = $scope.data.customerList[i++];){
						var object = {};
						object.id = customer.id;
						object.name = customer.name;
						arr.push(object);
					}
			 		
			 		CustUtil.openCustDialog("getMyUsableCustomers",function(data,innerWindow){
						$scope.$apply(function(){
							$scope.data.customerList = newList;
							
							//将重新选择的放入到List中
							for(var i = 0; i < data.length; i++) {
								var rights = {
									id : data[i].id,
									name : data[i].name,
									};
								$scope.data.customerList.push(rights);
							}
							});
					   $.Dialog.close(innerWindow);
					},arr);
			 	}
				
			} ]);

	/* 获取URL表单的 JSON 数据  必须以 getData为方法名*/
	function getData() {
		return AngularUtil.getScope().data;
	}
	/* 获取URL表单的校验情况，必须以isValid 为方法名 */
	function isValid() {
		//校验表单 ab-validate的 校验
		if (!ngUtil.getScope().form.$valid) {
			$.Dialog.error("表单校验不通过！");
			return false;
		}

		// 您可以自由的去做特殊业务逻辑的校验
		if (!ngUtil.getScope().data.content) {
			$.Dialog.error("跟进内容不可为空！");
			return false;
		}
		return true;
	}
</script>
<body class="panel success" ng-controller="ctrl">
	<!-- 顶部按钮 -->
	<div class="panel-heading">
		<a class="btn btn-primary fa-save" ng-model="data"  ab-save="/crm/customerFollowup/save"> 保存 </a>
		<a href="javascript:void(0)" class="btn btn-sm btn-primary fa-reply" onclick="javascript:$.Dialog.close(window);"> 返回 </a>
	</div>
	<!--  ab-load 去controller 层获取业务数据  -->
	<form name="form" method="post" ab-load="crm/customerFollowup/get?id={id}"
		ng-model="data">

		<table class="form-table">
			<tbody>
				<tr>
					<th>
						<span>客户名称</span>
						<span class="required">*</span>
					</th>
					<td>
						<span ng-repeat="customer in data.customerList" style="margin-right: 10px" class="label label-danger"> {{customer.name}}
						<span class="customerListButton"><button  href="javascript:void(0)" class="btn btn-link btn-default btn-xs" ng-click="ArrayTool.remove(customer,data.customerList)">×</button></span></span>
						<span class="btn  btn-sm btn-primary fa fa-search customerListSelect" ng-click="selectCustomerList()">选择</span> 
					</td>
				</tr>
				<tr>
					<th>跟进时间</th>
					<td><input class=" form-control"
						ng-model="data.followupTime" ab-validate="{}" id="followupTime"
						desc="跟进时间"
						ab-date="yyyy-MM-dd HH:mm:ss" /></td>
				</tr>
				<tr>
					<th>跟进内容</th>
					<td><textarea type="text" class=" form-control" id="content"
							ng-model="data.content"
							desc="跟进内容" ab-validate="{}"></textarea></td>
				</tr>
			</tbody>
		</table>
		
		
				
	</form>

</body>
















</html>